package com.example.servlet.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/*
    手动创建容器配置Servlet
 */
@WebServlet("/ServletDemo2")
public class ServletDemo2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Enumeration<String> names = req.getHeaderNames();
        resp.setContentType("text/html;charset=utf-8");
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String header = req.getHeader(name);
            resp.getWriter().write(name + "<___>" + header);
            resp.getWriter().write("<br>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
